package com.j180.dao.supGoods;


import com.j180.bean.SupGoods;
import com.j180.bean.SupGoodsCount;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 商品的持久层
 */
public interface ISupGoodsDao {

    /**
     * 查询某个供应商所供应的所有货品信息
     * @param id 供应商的id
     * @return 商品的信息
     */

    @Select("select sup.sug_id as suid," +
            "       sup.sug_name as suname, " +
            "       sup.sug_type as sutype," +
            "       sup.sug_material as sumaterial," +
            "       sup.sug_applicable as suapplicable," +
            "       sup.sug_exclusive as suexclusive," +
            "       sup.sug_packingSize as supackingSize," +
            "       sup.sug_flavor as suflavor," +
            "       sup.sug_function as sufunction," +
            "       sup.sug_origin as suorigin," +
            "       sup.sug_dateOfPro as sudateOfPro," +
            "       sup.sug_expDate as suexpDate," +
            "       sup.sug_supid as supid,"+
            "       sup.sug_explain as suexplain," +
            "       sup.sug_price as price," +
            "       sup.sug_pic as supic, " +
            "       supp.su_id as suppid, " +
            "       supp.su_name as suppname " +
            "       from t_supgoods as sup " +
            "  left join t_supplier as supp on sup.sug_su_id=supp.su_id" +
            "  where supp.su_id=#{id}")
    @ResultMap("mapper.resultMap.supGoodsMap")
    public List<SupGoods> getSupGoodsBySupplierId(@Param("id") int id);

    /**
     * 查询某个供应商的某个供应货品信息
     * @param suppId 供应商的id
     * @param supId 商品的id
     * @return
     */
    @Select("select sup.sug_id as suid, " +
            " sup.sug_name as suname," +
            "   sup.sug_type as sutype," +
            "       sup.sug_material as sumaterial," +
            "       sup.sug_applicable as suapplicable," +
            "       sup.sug_exclusive as suexclusive," +
            "       sup.sug_packingSize as supackingSize," +
            "       sup.sug_flavor as suflavor," +
            "       sup.sug_function as sufunction," +
            "       sup.sug_origin as suorigin," +
            "       sup.sug_dateOfPro as sudateOfPro," +
            "       sup.sug_expDate as suexpDate," +
            "       sup.sug_explain as suexplain," +
            "       sup.sug_price as suprice," +
            "       sup.sug_pic as supic," +
            "       supp.su_id as suppid," +
            "       supp.su_name as suppname from t_supgoods as sup " +
            " left join t_supplier as supp on sup.sug_su_id=supp.su_id" +
            " where supp.su_id=#{suppId} and sup.sug_id=#{supId}")
    @ResultMap("mapper.resultMap.supGoodsMap")
    public SupGoods getSupGoodsByIdAndSupplierId(@Param("suppId") int supId,@Param("supId")int suppId);

    /**
     * 供应商增加一种货品
     * @param supGoods
     * @return
     */


    @Insert("insert into t_supgoods  values(null,#{name},#{type},#{material},#{applicable},#{exclusive}," +
            "#{packingSize},#{flavor},#{function},#{origin},#{dateOfPro}," +
            "#{expDate},#{supId},#{explain},#{price},#{pic},#{supplier.id},#{store.id})")
    public int insertSupGoods(SupGoods supGoods);


    /**
     * 供应商取消供应某种货品
     * @param id 货品的id
     * @return
     */


    @Delete("delete from t_supgoods as sup where sup.sug_id=#{id}")
    public int delSupGoodsById(@Param("id") int id);





    /**
     * 供应商修改某种供应货品信息
     * @param supGoods
     * @return
     */
    @Update("update t_supgoods  set " +
            " sug_name=#{name}," +
            " sug_type=#{type}," +
            " sug_material=#{material}," +
            " sug_applicable=#{applicable}," +
            " sug_exclusive=#{exclusive}," +
            " sug_packingSize=#{packingSize}," +
            " sug_flavor=#{flavor}," +
            " sug_function=#{function}," +
            " sug_origin=#{origin}," +
            " sug_dateOfPro=#{dateOfPro}," +
            " sug_expDate=#{expDate}," +
            " sug_explain=#{explain}," +
            " sug_price=#{price}," +
            " sug_pic=#{pic} " +
            " where sug_id=#{id} ")
    public  int upSupGoods(SupGoods supGoods);


    /**
     * 根据供应商的id查询出门店基本信息和供应物品信息
     * @param id w供应商id
     * @return 查询结果
     */
    @Select("SELECT\n" +
            "\tstore.st_id,\n" +
            "\tstore.st_name as storeName,\n" +
            "\tsupgoods.sug_id,\n" +
            "\tsupgoods.sug_name  as sugGoodsName,\n" +
            "\tsupgoods.sug_price as price \n" +
            "FROM\n" +
            "\tt_supgoods AS supgoods\n" +
            "LEFT JOIN t_store AS store ON supgoods.sug_st_id = store.st_id\n" +
            "LEFT JOIN t_supplier AS supplier ON supgoods.sug_su_id = supplier.su_id\n" +
            "WHERE\n" +
            "\tstore.st_id =#{id}")
    public List<SupGoodsCount> getSupGoodsInfoBySupplierId(@Param("id")int id);

    @Select("select sup.sug_id as suid," +
            "       sup.sug_name as suname, " +
            "       sup.sug_type as sutype," +
            "       sup.sug_material as sumaterial," +
            "       sup.sug_applicable as suapplicable," +
            "       sup.sug_exclusive as suexclusive," +
            "       sup.sug_packingSize as supackingSize," +
            "       sup.sug_flavor as suflavor," +
            "       sup.sug_function as sufunction," +
            "       sup.sug_origin as suorigin," +
            "       sup.sug_dateOfPro as sudateOfPro," +
            "       sup.sug_expDate as suexpDate," +
            "       sup.sug_supid as supid,"+
            "       sup.sug_explain as suexplain," +
            "       sup.sug_price as price," +
            "       sup.sug_pic as supic, " +
            "       supp.su_id as suppid, " +
            "       supp.su_name as suppname " +
            "       from t_supgoods as sup " +
            "  left join t_supplier as supp on sup.sug_su_id=supp.su_id")
    @ResultMap("mapper.resultMap.supGoodsMap")
    List<SupGoods> getAllSupGoods();
}